<template>
    <div><h1>登录中</h1></div>
</template>

<script>
    import store from "../store";

    export default {
        name: "ToLogin",
        methods: {
            //解析url中的token参数
            getToken(){
                debugger
                var url = window.document.location.href.toString();//获得当前url地址并转换成字符串
                console.log(url)
                var u = url.split("?");
                //以？来分割字符串，将？前后的值存到一个数组中
                if(typeof(u[1]) == "string"){//获得？后面具体的请求参数值
                    u = u[1].split("&");
                    var get = {};
                    for(var i in u){
                        var j = u[i].split("=");
                        get[j[0]] = j[1];
                    }
                    return get;
                }
            }
        },
        created() {
            //获取到token 并封装到store中用于全程携带
            let token11=this.getToken();
            console.log(token11.uid+"===============")
            let uid = token11.uid
            let name = token11.name
            if (uid != undefined && uid != {}){
                /*localStorage.setItem('uid',uid)
                localStorage.setItem('name',name)*/
                //  var aaa = localStorage.getItem('token');
                //vuex
                this.$store.state.user.id=uid
                this.$store.state.user.name=name
                //跳转到首页
                this.$router.push('/home')
            }
        }
    }
</script>

<style scoped>

</style>
